<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>JS 对象</title>
</head>
<body>
    <h1>JS 对象</h1>
    <hr>
    <script>
        // Object 构造函数
    var obj1 = new Object();
    obj1.name = '静静';
    obj1.age = 19;
    obj1.getInfo = function(){
        document.write('OBJ<hr>');

    }

    console.log(obj1);
    obj1.getInfo();
    console.log(obj1.name);



        //  JSON 方式 (推荐)
        var obj2 = {
            age : 18,
            sex : '男',
            getInfo : function(){
                document.write('obj');

            }
        };
        obj2.name = '杨洋';
        console.log(obj2);
        obj2.getInfo();

         // 自定义构造函数
        function User(){
            // 属性
        this.name = '洋洋';
        this.age = 19;
        // 方法
        this.getInfo = function(){
            document.write('OBJ4 <br>');
            }
        }

    // console.log(User());
    var obj3 = new User();
    console.log(obj3);
    console.log(obj3.name);
    obj3.getInfo();


    // 匿名构造函数方式
    // 自定义构造函数 + 表达式方式
    var obj4 = new function(){
        // 属性
        this.name = '舒舒';
        this.age = 38;
        // 方法
        this.getInfo = function(){
            document.write('OBJ4 <br>');
        }
    }
    console.log(obj4);
    console.log(obj4.name);
    obj4.getInfo();

    console.log('obj1: ' + obj1.constructor);
    console.log('obj2: ' + obj2.constructor);
    console.log('obj3: ' + obj3.constructor);
    console.log('obj4: ' + obj4.constructor);
    console.log('一句话'.constructor);

    // var hh = document.getElementById('') // ID
    var hh = document.getElementsByTagName('h1');
    console.log(hh);
    console.log(hh.constructor);
    console.log(hh[0].constructor);

    </script>
    
    

</body>
</html>